package com.site.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/*session过滤器开启*/
@WebFilter("/admin/*")
public class SessionFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("session过滤器开启");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest requst = (HttpServletRequest)servletRequest;
        HttpSession session = requst.getSession();
        System.out.println("请求路径:"+requst.getServletPath());
        /*NewsUsers newsUsers = (NewsUsers) session.getAttribute("loginUser");
        if (newsUsers!=null && newsUsers.getUrole()==2){
            filterChain.doFilter(servletRequest,servletResponse);
        }else {
            System.out.println("权限不够");
            HttpServletResponse response = (HttpServletResponse) servletResponse;
            response.sendRedirect("/user.do?opr=doNews");
        }*/
    }

    @Override
    public void destroy() {
        System.out.println("session过滤器销毁");
    }
}
